<!DOCTYPE html>
<html>
<head>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>

<h1 id="title">数组测试</h1>

<script type="text/javascript">

    function log(value) {
        console.log(value);
    }
    var objs = [{name: "a", value: 1}, {name: "a", value: 2}, {name: "a", value: 4}, {name: "a", value: 5}, {name: "b", value: 1}]
    var src = new Array("a",objs,["a","c"]);

    src[1] = 1;
    src["a"] = "a";
    src["b"] = ["a", 123];
    src["objs"] = objs;



    var newQueryParams=new Array();
    $.each(objs, function () {//遍历并调用函数
        console.log(this);
        if(newQueryParams[this['name']]==undefined)//判断数组的key被设置了
        {
            newQueryParams[this['name']]=this['value'];
        }else{
            var oldValue =newQueryParams[this['name']];
            if(oldValue instanceof Array)//判断是否为数组
            {
                oldValue.push(this['value']);
            }else{
                var tempArr=new Array();
                tempArr.push(oldValue);//数组推入
                tempArr.push(this['value']);
                newQueryParams[this['name']]=tempArr;
            }
        }
    });

    //    src[] = 0;//不允许的

//    log(src);
    var result = new Array();


</script>
</body>
</html>

